package com.gdpu.project.dao.impl;

import java.util.List;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.hibernate.LockMode;
import org.springframework.context.ApplicationContext;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.gdpu.project.dao.ProEndDao;
import com.gdpu.project.vo.ProEnd;

/**
 * A data access object (DAO) providing persistence and search support for
 * ProEnd entities. Transaction control of the save(), update() and delete()
 * operations can directly support Spring container-managed transactions or they
 * can be augmented to handle user-managed Spring transactions. Each of these
 * methods provides additional information for how to configure it for the
 * desired type of transaction control.
 * 
 * @see com.gdpu.project.vo.ProEnd
 * @author MyEclipse Persistence Tools
 */

public class ProEndDaoImpl extends HibernateDaoSupport implements ProEndDao {
	private static final Log log = LogFactory.getLog(ProEndDaoImpl.class);
	// property constants
	public static final String PROJECT_ID = "projectId";
	public static final String TEACHER_ID = "teacherId";
	public static final String FILE_NAME = "fileName";
	public static final String FILE_PATH = "filePath";
	public static final String STATE = "state";
	public static final String COMMENT = "comment";

	protected void initDao() {
		// do nothing
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#save(com.gdpu.project.vo.ProEnd)
	 */
	public void save(ProEnd transientInstance) {
		log.debug("saving ProEnd instance");
		try {
			getHibernateTemplate().save(transientInstance);
			log.debug("save successful");
		} catch (RuntimeException re) {
			log.error("save failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#delete(com.gdpu.project.vo.ProEnd)
	 */
	public void delete(ProEnd persistentInstance) {
		log.debug("deleting ProEnd instance");
		try {
			getHibernateTemplate().delete(persistentInstance);
			log.debug("delete successful");
		} catch (RuntimeException re) {
			log.error("delete failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#findById(java.lang.Integer)
	 */
	public ProEnd findById(java.lang.Integer id) {
		log.debug("getting ProEnd instance with id: " + id);
		try {
			ProEnd instance = (ProEnd) getHibernateTemplate().get(
					"com.gdpu.project.vo.ProEnd", id);
			return instance;
		} catch (RuntimeException re) {
			log.error("get failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#findByExample(com.gdpu.project.vo.ProEnd)
	 */
	public List<ProEnd> findByExample(ProEnd instance) {
		log.debug("finding ProEnd instance by example");
		try {
			List<ProEnd> results = getHibernateTemplate().findByExample(instance);
			log.debug("find by example successful, result size: "
					+ results.size());
			return results;
		} catch (RuntimeException re) {
			log.error("find by example failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#findByProperty(java.lang.String, java.lang.Object)
	 */
	public List<ProEnd> findByProperty(String propertyName, Object value) {
		log.debug("finding ProEnd instance with property: " + propertyName
				+ ", value: " + value);
		try {
			String queryString = "from ProEnd as model where model."
					+ propertyName + "= ?";
			return getHibernateTemplate().find(queryString, value);
		} catch (RuntimeException re) {
			log.error("find by property name failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#findByProjectId(java.lang.Object)
	 */
	public List<ProEnd> findByProjectId(Object projectId) {
		return findByProperty(PROJECT_ID, projectId);
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#findByTeacherId(java.lang.Object)
	 */
	public List<ProEnd> findByTeacherId(Object teacherId) {
		return findByProperty(TEACHER_ID, teacherId);
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#findByFileName(java.lang.Object)
	 */
	public List<ProEnd> findByFileName(Object fileName) {
		return findByProperty(FILE_NAME, fileName);
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#findByFilePath(java.lang.Object)
	 */
	public List<ProEnd> findByFilePath(Object filePath) {
		return findByProperty(FILE_PATH, filePath);
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#findByState(java.lang.Object)
	 */
	public List<ProEnd> findByState(Object state) {
		return findByProperty(STATE, state);
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#findByComment(java.lang.Object)
	 */
	public List<ProEnd> findByComment(Object comment) {
		return findByProperty(COMMENT, comment);
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#findAll()
	 */
	public List<ProEnd> findAll() {
		log.debug("finding all ProEnd instances");
		try {
			String queryString = "from ProEnd";
			return getHibernateTemplate().find(queryString);
		} catch (RuntimeException re) {
			log.error("find all failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#merge(com.gdpu.project.vo.ProEnd)
	 */
	public ProEnd merge(ProEnd detachedInstance) {
		log.debug("merging ProEnd instance");
		try {
			ProEnd result = (ProEnd) getHibernateTemplate().merge(
					detachedInstance);
			log.debug("merge successful");
			return result;
		} catch (RuntimeException re) {
			log.error("merge failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#attachDirty(com.gdpu.project.vo.ProEnd)
	 */
	public void attachDirty(ProEnd instance) {
		log.debug("attaching dirty ProEnd instance");
		try {
			getHibernateTemplate().saveOrUpdate(instance);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	/* (non-Javadoc)
	 * @see com.gdpu.project.dao.impl.ProEndDao#attachClean(com.gdpu.project.vo.ProEnd)
	 */
	public void attachClean(ProEnd instance) {
		log.debug("attaching clean ProEnd instance");
		try {
			getHibernateTemplate().lock(instance, LockMode.NONE);
			log.debug("attach successful");
		} catch (RuntimeException re) {
			log.error("attach failed", re);
			throw re;
		}
	}

	public static ProEndDao getFromApplicationContext(ApplicationContext ctx) {
		return (ProEndDao) ctx.getBean("ProEndDAO");
	}
}